package com.lagou.edu.service.impl;

import com.lagou.edu.annotations.CustAutowired;
import com.lagou.edu.annotations.CustService;
import com.lagou.edu.annotations.CustTransactional;
import com.lagou.edu.dao.AccountDao;
import com.lagou.edu.pojo.Account;
import com.lagou.edu.service.TransferService;

/**
 * @author 应癫
 */
@CustTransactional
@CustService(value = "transferService")
public class TransferServiceImpl implements TransferService {

  @CustAutowired
  private AccountDao accountDao;


  @Override
  public void transfer(String fromCardNo, String toCardNo, int money) throws Exception {

    Account from = accountDao.queryAccountByCardNo(fromCardNo);
    Account to = accountDao.queryAccountByCardNo(toCardNo);

    from.setMoney(from.getMoney() - money);
    to.setMoney(to.getMoney() + money);

    accountDao.updateAccountByCardNo(to);
    System.out.println("1111111111111111111111111111:" + accountDao.queryAccountByCardNo(toCardNo));
    int c = 1 / 0;
    accountDao.updateAccountByCardNo(from);
  }
}
